package it.orma.iridehr.repository;

import it.orma.iridehr.entities.ConoscenzeInformatiche;
import it.orma.iridehr.entities.Parametro;
import it.orma.iridehr.entities.SchedaCandidato;
import it.orma.iridehr.entities.Users;

import java.util.Iterator;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public class ParametriRepository {
	
	static Logger log = LogManager.getLogger(CandidatoRepository.class);

	@PersistenceContext
	private EntityManager entityManager;
	
	public String ricercaParametro(String chiave){
		String queryHql = "select s.valore "+
				 " from "+Parametro.class.getCanonicalName()+" s"+
		         " where s.chiave =?"; 
		Query query = entityManager.createQuery(queryHql);
		query.setParameter(1, chiave);

		String valore = (String) query.getSingleResult();
		entityManager.detach(valore);
		return valore;
	}
	
	@Transactional
	public void salvaParametro(Parametro param) {
		Parametro param0 = entityManager.find(Parametro.class, param.getChiave());
		param0.setValore(param.getValore());
		entityManager.merge(param0);
		entityManager.flush();
		entityManager.detach(param0);
		entityManager.detach(param);
	}
	

}
